package ArrayList

import(
	"fmt"
)
//接口
type List interface{
	Size() int //数组大小
	Get(index int)(interface{})//抓取第几个元素
	Set(index int,newval interfase{} ) error //修改数据
	Insert(index int,newval interface{}) error //插入数据
	Append(newval interface{}) error //追加
	Clear() //清空
	Delete(index int)error //删除
	String() string //返回字符串
}

//数据结构，字符串，整数，实数
type ArrayList struct{
	dataStore [] interface{} //数组存储
	theSize int //数组的大小
}

func NewArrayList()*ArrayList{
	list:=new(ArrayList) //初始化结构体
	list.dataStore=make([]interface{},0,10)//开辟空间10个
	list.theSize=0
	return list
}

func(list *ArrayList)Size()int{
	return list.theSize //返回数据大小
}
func(list *ArrayList) Append(newval interface{}) error{
	list.dataStore=append(list.dataStore,newval) //叠加数据
	list.theSize++
}

func (list *ArrayList) Get(index int)(interface{}){
	if index<0 || index>=list.theSize{
		return nil,error.New("索引越界")
	}
	return list.dataStore[index],nil
}

func (list*ArrayList)String()string{
	return fmt.Sprint(list.dataStore)
}